#!/usr/bin/env python

#retrieves undeleted mail from the iphone image dump

import sqlite3

from time import strftime, localtime, gmtime
def run(s):
	#check if the file Envelope Index is there
	#try:
		print('Found "{}"'.format(s))
		#connect to the db

		conn = sqlite3.connect(s)
		c = conn.cursor()
		#print the column headers

		#get the table to print
		for rowid, sender, subject, _to, cc, date_sent, date_received, mailbox, remote_mailbox, original_mailbox, read, deleted, data in c.execute('select messages.rowid, sender, subject, _to, cc, date_sent, date_received, mailbox, remote_mailbox, original_mailbox, read, deleted, data from messages, message_data where message_data.message_id = messages.rowid'):
			

			#prints the values
			print('{0:10}{1:10}{2:10}{3:10}{4:10}{5:10}{6:10}{7:10}{8:10}{9:10}{10:10}{11:10}{12:10}'.format(rowid, sender, subject, _to, cc, date_sent, date_received, mailbox, remote_mailbox, original_mailbox, read, deleted, data))

		#endofloop
			
	# except sqlite3.Error:
	# 	print('The Envelope Index file is not placed in the current working directory')    

	

def main():
	#execute the operation on the sms.db file
	
	databaseName = 'Envelope Index'
	run(databaseName)

#exec main
if __name__ == '__main__':
	main()